var layerId;
var  clickState = true;
$(function(){
	$("#save-button").click(function(){
		var roleName = $("input[name='roleName']").val();
		var remark = $("input[name='remark']").val();
		if(roleName.length==0){
			layer.msg("角色名称不能为空");
			return false;
		}
		var treeObj=$.fn.zTree.getZTreeObj("permission-tree");
        var checkedNote=treeObj.getCheckedNodes(true);
        var menuArray = new Array();
        var permissionArray = new Array();
		for ( var j = 0; j < checkedNote.length; j++) {
			var id = checkedNote[j].id;
			var type = checkedNote[j].type;
			if(type == "menu"){
				menuArray.push(id);
			}else{
				permissionArray.push(id);
			}
		}
		
		var roleData ={
			"roleId":init.roleId,
			"roleName":roleName,
			"remark":remark,
			"menuIds":menuArray.toString(),
			"permissionIds":permissionArray.toString()
		}
		if(clickState){
			clickState = false;
			$.ajax({
				url:basePath+"/role/save.shtml",
				data:roleData,
				type:"post",
				dataType:"JSON",
				success:ajaxSuccessCloseFun
			});
		}
	});
	$("#close-button").click(function(){
		parent.closeLayer(0);
	});
	
});
